package me.zhengjie.modules.system.rest.machine;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.annotation.rest.AnonymousPostMapping;
import me.zhengjie.base.Code;
import me.zhengjie.modules.system.domain.req.BrandReqDTO;
import me.zhengjie.modules.system.domain.req.BrandReqQueryDTO;
import me.zhengjie.modules.system.domain.rsp.BrandRspDTO;
import me.zhengjie.modules.system.service.BrandService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author wx
 * @email
 * @date 2025-02-24 15:11:24
 */
@RestController
@RequestMapping("brand")
@Api(tags = "")
public class BrandController {

    @Resource
    private BrandService brandService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @PostMapping("/page")
    public PageResult<BrandRspDTO> page(@RequestBody BrandReqQueryDTO reqQueryDTO) {
        return brandService.findAll(reqQueryDTO);
    }


    /**
     * 保存
     */
    @ApiOperation(value = "保存")
    @AnonymousPostMapping("/save")
    public ResponseEntity<Boolean> save(@RequestBody BrandReqDTO reqDTO) {
        brandService.save(reqDTO);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody BrandReqDTO reqDTO) {
        brandService.update(reqDTO);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody Code code) {
        brandService.delete(code);
        return new ResponseEntity<>(HttpStatus.OK);

    }

    /**
     * 主键查询
     */
    @ApiOperation(value = "主键查询")
    @PostMapping("/findById")
    public ResponseEntity<BrandRspDTO> findById(@RequestBody Code code) {
        return new ResponseEntity<>(brandService.findById(code), HttpStatus.OK);
    }
}
